package com.lanou.controller;

import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by dllo on 18/2/26.
 */
@Controller
public class MainController {

    //首页
    @RequestMapping(value = "/")
    public String firstPage(){
        return "firstpage";
    }

    //登录
    @RequestMapping(value = {"/login"})
    public String home(){
        return "login";
    }


    @RequestMapping(value = "/loginsubmit")
    public ModelAndView loginsubmit(HttpServletRequest request) throws Exception {
        String error=null;
        String exName = (String) request.getAttribute("shiroLoginFailure");
        if (UnknownAccountException.class.getName().equals(exName)) {
            error= "账号不存在";
        } else if (IncorrectCredentialsException.class.getName().equals(exName)) {
            error= "密码错误";
        } else {
            error="不知为啥！";
        }
        ModelAndView mav=new ModelAndView("login");
        mav.addObject("error", error);
        return mav;

    }

    //注册
    @RequestMapping(value = "/register")
    public String register(){
        return "register";
    }
    //新建博客页
    @RequestMapping(value = "/newblog")
    public String newBlog(){
        return "newblog";
    }

    //博客详情页
    @RequestMapping(value = "/blogdesc")
    public String blogDesc(){
        return "/blogdesc";
    }
}
